package com.guc.coroutines.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.guc.coroutines.db.FileCache

/**
 * Created by guc on 2021/10/14.
 * Description：
 */
class FileCacheAdapter( var datas: ArrayList<FileCache>) : RecyclerView.Adapter<ViewHolder4RecyclerView>(){
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder4RecyclerView {
        val root: View = LayoutInflater.from(parent.context).inflate(android.R.layout.simple_list_item_1, parent, false)
        return ViewHolder4RecyclerView(root)
    }

    override fun getItemCount(): Int {
        return datas.size
    }

    override fun onBindViewHolder(holder: ViewHolder4RecyclerView, position: Int) {
        val item = datas[position]
        holder.setText(android.R.id.text1,item.toString())
    }

    fun add(fileCaches: List<FileCache>){
        this.datas.addAll(fileCaches)
        notifyDataSetChanged()
    }

    fun update(fileCaches:List<FileCache>){
        this.datas = arrayListOf()
        this.datas.addAll(fileCaches)
        notifyDataSetChanged()
    }
}



